#include <ctime>
#include <iostream>

#include "Task.hpp"
#include "ThreadPool.hpp"
using namespace std;

int main() {
  srand(time(nullptr));
  ThreadPool<Task> *tp =
      new ThreadPool<Task>();  // 参数传5 表示需要创建的线程池线程数量为5
  tp->Start();                 // 运行线程池
  string opers = "+-*/%";
  int len = opers.size();
  while (true) {
    // 1. 构建任务
    int num1 = rand() % 15;
    usleep(10);
    int num2 = rand() % 15;
    char op = opers[rand() % len];
    Task task(num1, num2, op);
    // 2. 将任务发送给线程池使其进行处理
    tp->Push(task);
    printf("The main thread send a task: %d %c %d = ?\n", num1, op, num2);
    sleep(1);
  }
  return 0;
}